// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   TestGateway.java

package cn.sendsms;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;
import org.apache.log4j.Logger;

// Referenced classes of package cn.sendsms:
//			AGateway, TimeoutException, GatewayException, FailureCauses, 
//			OutboundMessage, MessageStatuses

public class TestGateway extends AGateway
{

	private int refCounter;
	private int counter;
	protected int failCycle;

	public TestGateway(String id, Logger logger)
	{
		super(id, logger);
		refCounter = 0;
		counter = 0;
		attributes = 1;
		outbound = true;
		inbound = false;
	}

	public boolean sendMessage(OutboundMessage msg)
		throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		Thread.sleep(5000L);
		counter++;
		if (failCycle > 0 && counter >= failCycle)
		{
			msg.setFailureCause(FailureCauses.GATEWAY_FAILURE);
			failCycle = 0;
			return false;
		} else
		{
			msg.setDispatchDate(new Date());
			msg.setMessageStatus(MessageStatuses.SENT);
			msg.setRefNo(Integer.toString(++refCounter));
			msg.setGatewayId(getGatewayId());
			System.out.println("(" + getGatewayId() + ") Sent message to destination: " + msg.getRecipient() + ", text: " + msg.getText());
			return true;
		}
	}

	public int getFailCycle()
	{
		return failCycle;
	}

	public void setFailCycle(int failCycle)
	{
		this.failCycle = failCycle;
	}
}
